﻿using Books.Data.Model;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Books.Data
{
    public static class Seeder
    {
        public static void Seed(BooksDbContext context)
        {
            UserStore<User> store = new UserStore<User>(context);
            UserManager<User> manager = new UserManager<User>(store);

            User tre = manager.FindByEmail("tre@gmail.com");

            if (tre == null)
            {
                tre = new User
                {
                    Email = "tre@gmail.com",
                    UserName = "tre@gmail.com"
                };

                manager.Create(tre, "123456");
                tre = manager.FindByEmail("tre@gmail.com");
            }
            context.Books.AddOrUpdate(m => m.Title,
                new Book
                {
                    Title = "Atlas Shrugged",
                    Author = "Ayn Rand",
                    BookImage = "http://d.gr-assets.com/books/1405868167l/662.jpg",
                    Rating = 10,
                    User = tre
                },
                new Book
                {
                    Title = "Do Andriods Dream of Electric Sheep",
                    Author = "Phillip K. Dick",
                    BookImage = "http://www.solomonsays.in/web/imgs/review-images/47/Do-Androids-Dream-of-Electric-Sheep.jpg",
                    Rating = 7,
                    User = tre,
                },
                new Book
                {
                    Title = "Fountainhead",
                    Author = "Ayn Rand",
                    BookImage = "http://www.ayn-rand-quotes.com/wp-content/uploads/2014/01/the-fountainhead.jpg",
                    Rating = 10,
                    User = tre

                });
            
        }
    }
}
